package uk.ac.aber.Blockmation;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JLabel;
import uk.ac.aber.Blockmation.Actions.PlayMovieThread;

/**
 * Child class of Viewer that has limited features, but can notify when the
 * animation is finished, to then hide the splash screen
 * @author alex
 */
public class ViewerSplash extends Viewer implements KeyListener {
    
    private PlayMovieThread playMovieThread;
    
    ViewerSplash(MovieModel movieModel) {
        
        super(movieModel);
        
        JLabel escapeLabel = new JLabel("Press Any Key skip animation..");
        
        this.updateNewModel(movieModel);
        
        playMovieThread = new PlayMovieThread(this);
        playMovieThread.start();
        
        this.getContentPane().add(escapeLabel, BorderLayout.SOUTH);
        this.addKeyListener(this);
        
    }
    
    public boolean getStatus() {
        long delayMillis = 7000; 
        try {
            playMovieThread.join(delayMillis);

            if (playMovieThread.isAlive()) {
                return true;
            } else {
                return false;
            }
        } catch (InterruptedException e) {
            return false;
        }
  
    }

    public void keyPressed(KeyEvent e) {
        playMovieThread.interrupt();
    }
    
    public void keyTyped(KeyEvent e) {}

    public void keyReleased(KeyEvent e) {}

}
